package com.xuxu.member.service;

import com.baidu.aip.face.AipFace;
import org.aspectj.util.FileUtil;
import org.json.JSONObject;
import org.springframework.stereotype.Service;

import java.util.Base64;
import java.util.HashMap;

/**
 * @className: FaceService
 * @author: Maxuxu
 * @date: 2022/8/19 21:47
 * @description: 人脸识别服务
 */
@Service
public class FaceService {
    //设置APPID/AK/SK
    private static final String APP_ID = "27085776";

    private static final String API_KEY = "w5ZWxFkRW6Azq5otzcGK8Lsf";

    private static final String SECRET_KEY = "rjrZ6kRGlcG5bLnZdh88p10VHxG43hBh";

    public static void main(String[] args) {
        // 初始化一个AipFace
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("user_info", "user's info");
        options.put("quality_control", "NORMAL");
        options.put("liveness_control", "LOW");
        options.put("action_type", "REPLACE");
        String image = "http://tamad.fun:9001/images/2022/08/14/202208141530301.png";
        String imageType = "BASE64";
        String groupId = "group1";
        String userId = "user1";

        // 人脸注册
        JSONObject res = client.addUser(image, imageType, groupId, userId, options);
        System.out.println(res.toString(2));


    }

}
